package SerializerTest;

import com.caucho.hessian.io.Hessian2Input;
import com.caucho.hessian.io.Hessian2Output;
import com.caucho.hessian.io.HessianOutput;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;


//Hessian序列化
public class Hession_test {

    public static void main(String[] args) throws IOException {
        //serialize
        ByteArrayOutputStream bos=new ByteArrayOutputStream();
        Hessian2Output out=new Hessian2Output(bos);
        out.startMessage();
        person person=new person(18,"tom");
        out.writeObject(person);
        out.completeMessage();
        out.close();
        byte[] bytes = bos.toByteArray();
        //deserialize
        ByteArrayInputStream bis=new ByteArrayInputStream(bytes);
        Hessian2Input input=new Hessian2Input(bis);
        input.startMessage();
        person person1 = (person)input.readObject(person.getClass());
        System.out.println(person1.age);
        System.out.println(person1.name);
        input.completeMessage();
    }
}

class person implements Serializable {
    int age;
    String name;

    public person(int age,String name){
        this.age=age;
        this.name=name;
    }
}
